// featurePackage/pages/myScore/myScore.js
const app = getApp()
import {
  extractRecord,
} from "../../../service/jb_scoreAndMoney_service"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    navBarHeight: app.globalData.menuButton.top + app.globalData.menuButton.height,
    dataList: [
      // {
      //   extractType: "bank",
      //   alipayCode: "3483843",
      //   extractPrice: "18.4",
      //   createTime: "2024-03-12 12:34:00",
      //   updateTime: "2024-03-12 12:34:00",

      // }
    ],
    scoreDetail: {
      integral: 0,
      sumIntegral: 0,
      deductionIntegral: 0,
      frozenIntegral: 0,//冻结积分
    },
    isShowLoading: false,//加载状态出现
    isBottomShow: false,//是否没有更多数据了
    refreshFlag: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.queryScoreChangeList('refresh');
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  //积分变动列表
  queryScoreChangeList(type) {
    wx.showLoading();
    extractRecord(this.data.page, this.data.limit).then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.dataList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          dataList: arr,
          refreshFlag: false,
          isShowLoading: false,
          isBottomShow: res.data.totalPage == this.data.page ? true : false,
        })
      }
    }).catch(err => {
      console.error("JJLog:extractRecord", err);
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.page != 1) {
        this.setData({
          page: this.data.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
    })
  },

  // 下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryScoreChangeList('refresh');

  },

  // 加载更多
  handleLoadmore() {
    console.log('加载更多');
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      page: this.data.page + 1
    })
    this.queryScoreChangeList()
  },



})